home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / filters.zip / TRANSLAT.ASM < prev    next >
Assembly Source File  |  1986-11-27  |  3KB  |  152 lines

  1.     Name translat
  2.     Title
  3.     page    ,132
  4. comment /
  5.  
  6.     This program is a filter that reads a file and changes each
  7.     sentence into the individual words, one word per line.
  8.     Only alphabetic characters are retained - no case changes are
  9.     performed.
  10.  
  11. /
  12. ;===================================================================
  13. code    segment    public
  14. ;===================================================================
  15. ;
  16. ;    command line is at 80h of psp - first byte is length
  17. ;
  18.     org    80h
  19. parmsize    db    ?
  20. parm        db    7fh dup (?)
  21. ;
  22. ; .com starts at 100h - but must jump around any data area
  23. ;
  24.     org    100h            ; com file starts here
  25.     assume    cs:code,ds:code,es:code
  26. translat proc far
  27.     jmp    clear
  28. ;===================================================================
  29. ;
  30. ; data area for .com programs
  31. ;
  32. bufsiz        equ    80    ; hadn't better be words this long!
  33. inchar      db    ?
  34. buffer        db    bufsiz dup (?)
  35. count        dw    0
  36. crlf        db    13,10    ; end of line string
  37. ;
  38. ;===================================================================
  39. clear:
  40. ;
  41. ; start of actual code is here (clear)
  42. ;
  43. ;
  44. ; Read a character.  If it is a-z or A-Z copy it to the output buffer
  45. ; and increment count.  If not, send the output buffer and enter
  46. ; bypass loop until alpha character is read again.
  47. ;
  48. ;
  49.     lea    di,buffer    ; set up output pointer
  50. again:
  51. ;
  52. ; read a character
  53. ;
  54.     xor    bx,bx        ; zero is handle of standard input
  55.     mov    cx,1h        ; get 1 character
  56.     lea    dx,inchar    ; offset of inchar
  57.     mov    ah,3fh        ; read a file/device function
  58.     int    21h        ; invoke the function
  59. ;
  60. ; if carry set of ax=0 exit
  61. ;
  62.     jc    oops        ; i/o error
  63.     and    ax,ax        ; set flags
  64.     jz    oops        ; eof
  65. ;
  66. ; Now check for alpha character.
  67. ;
  68.     mov    al,inchar
  69.     call     isalpha        ; proc sets carry flag if not alpha
  70.     jc    output
  71. ok:
  72.     inc    count
  73.     stosb
  74.     jmp    again
  75. output:
  76.     mov    bx,1h        ; standard output handle
  77.     lea    dx,buffer    ;
  78.     mov    cx,count    ; get # of char to output
  79.     mov    ah,40h        ;
  80.     int    21h        ; call dos output function
  81.     call outcrlf
  82. skip:
  83. ;
  84. ; read a character until alphabetic.
  85. ;
  86.     xor    bx,bx        ; zero is handle of standard input
  87.     mov    cx,1h        ; get 1 character
  88.     lea    dx,inchar    ; offset of inchar
  89.     mov    ah,3fh        ; read a file/device function
  90.     int    21h        ; invoke the function
  91. ;
  92. ; if carry set of ax=0 exit
  93. ;
  94.     jc    oops        ; i/o error
  95.     and    ax,ax        ; set flags
  96.     jz    oops        ; eof
  97. ;
  98. ; now check it - if alpha, reset else skip again
  99. ;
  100.     mov    al,inchar
  101.     call    isalpha
  102.     jc    skip
  103. ;
  104. ; character is alpha - reset buffer and jump to top again.
  105. ;
  106.     mov    count,1h    ; reset count
  107.     lea    di,buffer     ; reset buffer
  108.     stosb
  109.     jmp    again        ; repeat cycle
  110. oops:
  111.     cmp    count,0h    ; if something in buffer, output it.
  112.     jz    exit
  113. ;
  114.     mov    bx,1h        ; standard output handle
  115.     lea    dx,buffer    ;
  116.     mov    cx,count    ; get # of char to output
  117.     mov    ah,40h        ;
  118.     int    21h        ; call dos output function
  119.     call    outcrlf
  120. exit:
  121.     int    20h        ; return to dos
  122. translat    endp
  123. ;
  124. ;
  125. isalpha    proc    near
  126.     stc            ; assume bad
  127.     cmp    al,'A'        ; if <A or >z then bad
  128.     jb    notalpha    ;
  129.     cmp    al,'z'
  130.     ja    notalpha
  131.     cmp    al,'Z'        ; if <=Z or >=a then ok
  132.     jbe    yesalpha
  133.     cmp    al,'a'
  134.     jb     notalpha
  135. yesalpha:
  136.     clc
  137. notalpha:
  138.     ret
  139. isalpha    endp
  140. ;
  141. outcrlf    proc    near
  142.     mov    bx,1h        ; standard output handle
  143.     lea    dx,crlf      ;
  144.     mov    cx,2h       ; get # of char to output
  145.     mov    ah,40h        ;
  146.     int    21h        ; call dos output function
  147.     ret
  148. outcrlf    endp
  149. ;
  150. code    ends
  151.     end    translat
  152.